package com.iweb.servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet(name = "AdminServlet",urlPatterns = {"/servlet/"})
public class AdminServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String option = req.getParameter("option");
        String path = req.getContextPath();
        if ("login".equals(option)) {
            String username = req.getParameter("username");
            String password = req.getParameter("password");
            if ("admin".equals(username)&&"123456".equals(username)) {
                HttpSession session = req.getSession();
                session.setAttribute("loginUser",username);
                resp.sendRedirect(path+"/admin/admin.jsp");
            }else{
                resp.sendRedirect(path+"/login.jsp");
            }
        }
    }
}
